<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>注册一个并行的服务调用</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.yar-concurrent-client.html">Yar_Concurrent_Client</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="yar-concurrent-client.loop.html">Yar_Concurrent_Client::loop</a></div>
 <div class="up"><a href="class.yar-concurrent-client.html">Yar_Concurrent_Client</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="yar-concurrent-client.call" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Yar_Concurrent_Client::call</h1>
  <p class="verinfo">(PECL yar &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Yar_Concurrent_Client::call</span> &mdash; <span class="dc-title">注册一个并行的服务调用</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-yar-concurrent-client.call-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">int</span> <span class="methodname"><strong>Yar_Concurrent_Client::call</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$uri</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$method</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$parameters</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   注册一个并行的(异步的)远程服务调用, 不过这个调用请求不会被立即发出,
   而是会在接下来调用
   <span class="methodname"><a href="yar-concurrent-client.loop.html" class="methodname">Yar_Concurrent_Client::loop()</a></span>的时候才真正的发送出去.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-yar-concurrent-client.call-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<em><code class="parameter">uri</code></em></dt>

    <dd>

     <p class="para">
      服务的URL.
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">method</code></em></dt>

    <dd>

     <p class="para">
      调用的服务名字(也就是服务方法名).
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">parameters</code></em></dt>

    <dd>

     <p class="para">
      调用的参数.
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">callback</code></em></dt>

    <dd>

     <p class="para">
      回掉函数, 在远程服务的返回到达的时候被Yar调用, 从而可以处理返回内容.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-yar-concurrent-client.call-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回一个整数值(sequence), 可以用来区分到底是那个调用的返回.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-yar-concurrent-client.call-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-5226">
   <p><strong>Example #1 <span class="function"><strong>Yar_Concurrent_Client::call()</strong></span>示例</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">callback</span><span style="color: #007700">(</span><span style="color: #0000BB">$retval</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$callinfo</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$retval</span><span style="color: #007700">);<br />}<br /><br />function&nbsp;</span><span style="color: #0000BB">error_callback</span><span style="color: #007700">(</span><span style="color: #0000BB">$type</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$error</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$callinfo</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">error_log</span><span style="color: #007700">(</span><span style="color: #0000BB">$error</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">Yar_Concurrent_Client</span><span style="color: #007700">::</span><span style="color: #0000BB">call</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://host/api/"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"some_method"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"parameters"</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"callback"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">Yar_Concurrent_Client</span><span style="color: #007700">::</span><span style="color: #0000BB">call</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://host/api/"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"some_method"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"parameters"</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;if&nbsp;the&nbsp;callback&nbsp;is&nbsp;not&nbsp;specificed,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;callback&nbsp;in&nbsp;loop&nbsp;will&nbsp;be&nbsp;used<br /></span><span style="color: #0000BB">Yar_Concurrent_Client</span><span style="color: #007700">::</span><span style="color: #0000BB">call</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://host/api/"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"some_method"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"parameters"</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"callback"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">YAR_OPT_PACKAGER&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"json"</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//this&nbsp;server&nbsp;accept&nbsp;json&nbsp;packager<br /></span><span style="color: #0000BB">Yar_Concurrent_Client</span><span style="color: #007700">::</span><span style="color: #0000BB">call</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://host/api/"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"some_method"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"parameters"</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"callback"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">YAR_OPT_TIMEOUT</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">1</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//custom&nbsp;timeout&nbsp;<br /><br />//&nbsp;这个时候请求都还没有发出<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
</pre></div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-yar-concurrent-client.call-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="methodname"><a href="yar-concurrent-client.loop.html" class="methodname" rel="rdfs-seeAlso">Yar_Concurrent_Client::loop()</a> - 发送所有注册的并行调用</span></li>
   <li class="member"><span class="methodname"><a href="yar-server.construct.html" class="methodname" rel="rdfs-seeAlso">Yar_Server::__construct()</a> - 创建一个HTTP RPC Server</span></li>
   <li class="member"><span class="methodname"><a href="yar-server.handle.html" class="methodname" rel="rdfs-seeAlso">Yar_Server::handle()</a> - 启动HTTP RPC Server</span></li>
  </ul>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.yar-concurrent-client.html">Yar_Concurrent_Client</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="yar-concurrent-client.loop.html">Yar_Concurrent_Client::loop</a></div>
 <div class="up"><a href="class.yar-concurrent-client.html">Yar_Concurrent_Client</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
